import Fields from 'dependencies/Fields'
import Field from 'dependencies/Field'
import DetailImgs  from 'modules/component/DataView/DetailImgs'
import { UniImageUpload } from 'modules/component/upload'
import { getEnums } from 'dependencies/api/templateClass'
import { getFileCategories } from 'dependencies/api/index'
import selectWordType  from 'pages/avatar-template/components/selectWordType'
import uploadMainBg  from 'pages/avatar-template/components/uploadMainBg'

import { PromiseEnums } from 'dependencies/PromiseEnums'
let classEnums = new PromiseEnums([])
  .setFetchEnumsCallback(getEnums)
  .setCustomKeyValues('class_name', '_id')
  
let fileCategoriesEnums = new PromiseEnums([])
  .setFetchEnumsCallback(getFileCategories)
  .setCustomKeyValues('name', '_id')
console.log(fileCategoriesEnums.enums)

export const template_id = new Field({
  prop: 'template_id',
  label: '模板ID'
})
export const name = new Field({
  prop: 'name',
  label: '模板名称',
  required: true
})
export const class_id = new Field({
  prop: 'class_id',
  label: '分类',
  type: 'select',
  required: true,
  enums: classEnums.enums
})

export const is_online = new Field({
  prop: 'is_online',
  label: '是否上线生产',
  required: true,
  type: 'radio',
  enums: [
    { value: 1, label:"是"},
    { value: 0, label:"否"}
  ]
})
export const previewUrl = new Field({
  prop: 'previewUrl',
  required: true,
  label: '预览图'
})
export const path = new Field({
  prop: 'path',
  required: true,
  label: '页面url'
})
export const order = new Field({
  prop: 'order',
  required: true,
  label: '排序',
  type: 'number'
})
export const shareText = new Field({
  prop: 'shareText',
  required: true,
  label: '分享文案'
})
export const downloadPrice = new Field({
  prop: 'downloadPrice',
  label: '下载头像价格',
  required: true,
  type: 'number'
})
export const salePrice = new Field({
  prop: 'salePrice',
  required: true,
  label: '购买价格',
  type: 'number'
})
export const isSupportAdLoad = new Field({
  prop: 'isSupportAdLoad',
  label: '支持看视频下载头像',
  required: true,
  type: 'radio',
  enums: [
    { value: 0, label:"不支持"},
    { value: 1, label:"支持"}
  ]
})

export const isPackageImg = new Field({
  prop: 'isPackageImg',
  label: '是否是图片包',
  required: true,
  type: 'radio',
  enums: [
    { value: 0, label:"否"},
    { value: 1, label:"是"}
  ]
})
export const packageId = new Field({
  prop: 'packageId',
  label: '关联图片包',
  required: true,
  type: 'select',
  enums: fileCategoriesEnums.enums
})

export const packageDownloadUrl = new Field({
  prop: 'packageDownloadUrl',
  label: '整包下载地址'
})

export const componentClass = new Field({
  prop: 'componentClass',
  label: '模板样式',
  required: true
})

export const homophonicWordColor = new Field({
  prop: 'homophonicWordColor',
  type: 'color',
  required: false,
  label: '谐音词颜色'
})

export const manWordBg = new Field({
  prop: 'manWordBg',
  required: true,
  label: '男孩姓氏高亮背景图'
})

export const femaleWordBg = new Field({
  prop: 'femaleWordBg',
  required: true,
  label: '女孩姓氏高亮背景图'
})

export const mainBgList = new Field({
  prop: 'mainBgList',
  required: true,
  label: '主图列表'
})

export const templateTableFields = Object.freeze([
  template_id,
  name,
  is_online,
  class_id,
  isPackageImg,
  previewUrl.setListComponent(DetailImgs),
  downloadPrice.setListComponent({
    props: {
      value: Number
    },
    render(h) {
      return h('span', '￥' + vk.pubfn.priceFilter(this.value) || '--')
    }
  }),
  salePrice.setListComponent({
    props: {
      value: Number
    },
    render(h) {
      return h('span', '￥' + vk.pubfn.priceFilter(this.value) || '--')
    }
  }),
  path,
  order,
  shareText,
  isSupportAdLoad
])

export const queryListFields = [
  name,
  class_id
]
export const columns = [{
    key: "name",
    title: "name",
    type: "text"
  },
  {
      key: "class_id",
      title: "class_id",
      type: "text"
    }
]
export const templateCreateFields = new Fields([
  name,
  previewUrl.setEditComponent(UniImageUpload),
  is_online,
  downloadPrice,
  salePrice,
  path,
  order,
  shareText,
  class_id,
  isPackageImg,
  packageId.setShowCondition(context => context.data[isPackageImg.prop] === 1),
  packageDownloadUrl.setShowCondition(context => context.data[isPackageImg.prop] === 1),
  componentClass.setEditComponent(selectWordType).setShowCondition(context => context.data[isPackageImg.prop] === 0),
  homophonicWordColor.setShowCondition(context => {
    return context.data[isPackageImg.prop] === 0 && context.data[componentClass.prop] <= 4
  }).setCustomize('常用颜色：褐色：#75221d， 蓝色 #3e5a98'),
  manWordBg.setShowCondition(context => {
    return context.data[isPackageImg.prop] === 0
  }).setEditComponent(UniImageUpload),
  femaleWordBg.setShowCondition(context => {
    return context.data[isPackageImg.prop] === 0
  }).setEditComponent(UniImageUpload),
  mainBgList.setShowCondition(context => {
    return context.data[isPackageImg.prop] === 0
  }).setEditComponent(uploadMainBg)
])